home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-24 | 19.2 KB | 438 lines | [TEXT/CCL ] |
- ; (c) Copyright 1990 by University of Massachusetts. All rights reserved.
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; Mr. Suthers created this software under his own initiative while in an
- ; academic relationship with the University of Massachusetts. The above
- ; copyright notice was a condition placed by University lawyers on approval
- ; of distribution of this software by Apple Computer, and is not meant to
- ; imply that this software was created in an employment or "work for hire"
- ; relationship between the University and Mr. Suthers.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; File: DNET-BROWSER.lisp
- ; Author: Dan Suthers
- ; Created: 25-May-88 22:54:37
- ; Modified: 22-Jun-90 02:34:16 (Dan Suthers)
- ; Language: LISP
- ; Package: DNET
- ;
- ; Description: Browser of the contents of a DNET.
- ;
- ; (c) Copyright 1988, by Daniel D. Suthers
- ; Department of Computer and Information Science
- ; University of Massachusetts
- ; Amherst, Massachusetts 01003
- ;
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; I wish to acknowledge the generous support of Beverly Woolf, who obtained
- ; the above grants and encouraged me to pursue my own research interests in
- ; her lab. This work would not have been possible without the resources and
- ; stimulating environment of the Computer and Information Science department.
- ;
- ; Permission to use, modify, and distribute this software is granted subject
- ; to the following restrictions and understandings:
- ; 1. The file header, including this notice, shall be retained, and may be
- ; extended to include documentation of modifications to the software.
- ; 2. This material is for nonprofit educational and research purposes only.
- ; Users are requested, but not required, to inform Mr. Suthers of any
- ; noteworthy uses of this software.
- ; 3. Mr. Suthers and the University of Massachusetts make no warrantee or
- ; representation that the operation of this software will be error free,
- ; and are under no obligation to provide any services.
- ; 4. Any user of such software agrees to indemnify and hold harmless Mr.
- ; Suthers and the University of Massachusetts from all claims arising
- ; out of the use or misuse of this software, or arising out of any
- ; accident, injury, or damage whatsoever, and from all costs, counsel
- ; fees, and liabilities incurred in or about any such claim, action, or
- ; proceeding brought thereon.
- ; 5. All materials and reports developed as a consequence of the use of
- ; this software shall duly acknowledge such use, in accordance with
- ; the usual standards of acknowledging credit in academic research.
- ;
- ; Status: Works, but this is a primitive interface. I recommend
- ; loading DNETs from other easier to edit data structures.
- ;
- ; Tested: Macintosh II Coral/Allegro 19-Jul-88 16:22:16
- ;
- ; Changes:
- ;
- ; 08-Jun-88 Choice of build or browse default actions in browse-dnet.
- ; 19-Jul-88 Save Dnet menu gives default path.
- ; 23-Jul-88 No longer display bindings, for efficiency and readability.
- ; They are usually obvious. Instead, info & bindings buttons give you
- ; this further information on the most recently retrieved expressions.
- ; 25-Jan-90 Fixed bug in asking dead menu to install itself.
- ; 30-Jan-90 Updated for version 1.3.1: :default-button now in buttons.
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package :DNET)
-
- (export '(
- browse-dnets
- ))
-
- (require :DIALOGUE)
- (require :SM )
- (require :SMEDIT )
- (require :DNET )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; For convenience of the user
-
- (defvariable x)
- (defvariable y)
- (defvariable z)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defconstant *help-string*
- "To Use:
- 1. Select a discrimination net from the menu. (You may make new nets via
- the Structure Manager Browser.)
- 2. Enter retrieval expression or pattern above (in smaller text window).
- 3. Select the desired action button:
- - Retrieve Pattern retrieves and prints all expressions in the DNET
- matching the pattern you typed in (variables used).
- - Retrieve Expression retrieves and prints all expressions OR patterns
- in the DNET matching your expression (variables not used).
- - Add and Delete perform the indicated operation on the expression
- you gave.
- - Show Info and Bindings show the corresponding information for
- the last set of retrieved expressions.")
-
- (defun BROWSE-DNETS (&optional (build-mode nil))
- "browse-dnets &optional <build-mode> [Function]
- Puts up a discrimination net browser. If <build-mode> is nil (default),
- the default button is for pattern retrieval; if T, the default is for
- adding an expression."
- (macrolet ((with-selected-dnet (body)
- ;; Binds dnet to the dnet selected and executes body, unless error.
- `(let ((dnet
- (ccl:ask dnet-menu
- (if (ccl:selected-cells)
- (ccl:cell-contents (car (ccl:selected-cells)))))))
- (if (null dnet)
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (concatenate 'string "You must select a DNET first.
- "
- *help-string*)))
- ,body)))
- (with-selected-expression (body)
- ;; Binds expression to the retrieved expression, and dnet to the
- ;; dnet it is in, and executes body; unless an error is encountered
- ;; in the process.
- `(let ((expression-string
- (ccl:ask entry-window (ccl:dialog-item-text)))
- (expression nil)
- (dnet
- (ccl:ask dnet-menu
- (if (ccl:selected-cells)
- (ccl:cell-contents (car (ccl:selected-cells)))))))
- (cond
- ((null dnet)
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (concatenate 'string "You must select a DNET first.
- "
- *help-string*))))
- ((and expression-string dnet)
- (setf expression (read-from-string expression-string nil '$eof$))
- (if (eq expression '$eof$)
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- "Error on read of your expression."))
- ,body))))))
- (let*
- (
- ;; These are used to communicate between buttons.
- (retrieved-expressions nil)
- (retrieved-bindings nil)
-
- ;;----------------
- ;; Display Windows
-
- ;; Window in which user types retrieval patterns.
- (entry-window
- (ccl:oneof ccl:*editable-text-dialog-item*
- :dialog-item-size (ccl:make-point 575 50)
- :dialog-item-position (ccl:make-point 8 80)
- :dialog-item-font '("monaco" 12)
- :dialog-item-text ""
- :allow-returns nil))
-
- ;; Window where the retrieved patterns are displayed.
- (display-window
- (ccl:oneof ccl:*editable-text-dialog-item*
- :dialog-item-size (ccl:make-point 575
- (if build-mode 130 230))
- :dialog-item-position (ccl:make-point 8 145)
- :dialog-item-font '("monaco" 12)
- :dialog-item-text *help-string*
- :allow-returns t))
-
- ;;-----------------------------
- ;; Menu for selecting the DNET.
- (dnet-menu
- (ccl:oneof ccl:*sequence-dialog-item*
- :dialog-item-size (ccl:make-point 150 84)
- :dialog-item-position (ccl:make-point 420 15)
- :table-vscrollp t
- :table-hscrollp nil
- :visible-dimensions (ccl:make-point 1 3)
- :cell-size (ccl:make-point 140 16)
- :table-sequence
- (sm:instances 'dnet)
- :sequence-order :vertical))
-
- ;;-----------------------------------------
- ;; Buttons left to right across the top ...
-
- ;; Retrieve based on the current pattern.
- (retrieve-pattern
- (ccl:oneof
- ccl:*button-dialog-item*
- :dialog-item-text "Retrieve Pattern"
- :dialog-item-position (ccl:make-point 10 15)
- :dialog-item-enabled-p t
- :dialog-item-action
- #'(lambda ()
- (with-selected-expression
- (ccl:ask
- display-window
- (multiple-value-setq
- (retrieved-expressions retrieved-bindings)
- (match-pattern expression dnet))
- (ccl:set-dialog-item-text
- (let ((*print-pretty* t))
- (format nil "~{~S~%~}" retrieved-expressions))))))
- :default-button (not build-mode)))
-
- ;; Retrieve based on the current expression (not pattern).
- (retrieve-expression
- (ccl:oneof
- ccl:*button-dialog-item*
- :dialog-item-text "Retrieve Expression"
- :dialog-item-position (ccl:make-point 10 47)
- :dialog-item-enabled-p t
- :dialog-item-action
- #'(lambda ()
- (with-selected-expression
- (ccl:ask
- display-window
- (multiple-value-setq
- (retrieved-expressions retrieved-bindings)
- (match-expression expression dnet))
- (ccl:set-dialog-item-text
- (let ((*print-pretty* t))
- (format nil "~{~S~%~}" retrieved-expressions))))))))
-
- ;; Add an expression
- (add-expression
- (ccl:oneof
- ccl:*button-dialog-item*
- :dialog-item-text "Add Expression"
- :dialog-item-position (ccl:make-point 166 15)
- :dialog-item-enabled-p t
- :dialog-item-action
- #'(lambda ()
- (with-selected-expression
- (multiple-value-bind
- (added-p terminal)
- (indexpr expression dnet)
- (declare (ignore terminal))
- (if added-p
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (format nil "~%~S added to ~S" expression dnet)))
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (format nil "~%~S Already Present in ~S"
- expression dnet)))))))
- :default-button build-mode))
-
- ;; Delete expression.
- (delete-selected
- (ccl:oneof
- ccl:*button-dialog-item*
- :dialog-item-text "Delete Expression"
- :dialog-item-position (ccl:make-point 166 47)
- :dialog-item-enabled-p t
- :dialog-item-action
- #'(lambda ()
- (with-selected-expression
- (if (delexpr expression dnet)
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (format nil "~%~S Deleted from ~S"
- expression dnet)))
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (format nil "~%~S was not found in ~S"
- expression dnet))))))))
-
- ;; Property list manipulation.
- (show-expr-info
- (ccl:oneof
- ccl:*button-dialog-item*
- :dialog-item-text "Show Info"
- :dialog-item-position (ccl:make-point 305 15)
- :dialog-item-enabled-p t
- :dialog-item-action
- #'(lambda ()
- (with-selected-dnet
- (ccl:ask display-window
- (ccl:set-dialog-item-text
- (format nil "~{~S~% Info: ~S~%~%~}"
- (mapcan #'(lambda (e) (list e (expr-info e dnet)))
- retrieved-expressions))))))))
-
- ;; Editing info done by EDITS (Fred window). Only the INFO is displayed,
- ;; as the EXPR cannot be edited without reindexing.
- (show-bindings
- (ccl:oneof
- ccl:*button-dialog-item*
- :dialog-item-text "Show Bindings"
- :dialog-item-position (ccl:make-point 305 47)
- :dialog-item-enabled-p t
- :dialog-item-action
- #'(lambda ()
- (ccl:ask
- display-window
- (ccl:set-dialog-item-text
- (format nil "~{~S~% Bindings: ~S~%~%~}"
- (do ((eptr retrieved-expressions (cdr eptr))
- (bptr retrieved-bindings (cdr bptr))
- (result (list :head)))
- ((null eptr) (cdr result))
- (nconc result (list (first eptr) (first bptr))))))))))
-
- ;; Create the browser window itself.
- (browser
- (ccl:oneof ccl:*dialog*
- :window-title (if build-mode
- " Discrimination Net Builder "
- " Discrimination Net Browser ")
- :window-position (ccl:make-point 25 45)
- :window-size (ccl:make-point 592 (if build-mode 285 385))
- :window-type :tool
- :dialog-items (list retrieve-expression retrieve-pattern
- add-expression delete-selected
- show-expr-info show-bindings
- dnet-menu
- entry-window
- display-window))))
- browser)))
-
- (defparameter *DNET-MENU*
- (let* ((line-item
- (ccl:oneof ccl:*menu-item*
- :menu-item-title "-"))
- (browse-item
- (ccl:oneof ccl:*menu-item*
- :menu-item-title "DNET Browser ..."
- :menu-item-action
- #'(lambda ()
- (browse-dnets
- (not
- (wind:y-or-n-dialogue
- "Is your primary activity Browsing (as opposed to building)?"))))))
- (destroy-dnet-item
- (ccl:oneof ccl:*menu-item*
- :menu-item-title "Destroy DNET ..."
- :menu-item-action
- #'(lambda ()
- (let ((dnet
- (wind:menu-dialogue
- (sm:instances 'dnet)
- "Destroy which DNET?")))
- (destroy-dnet dnet)))))
- (save-dnet-item
- (ccl:oneof
- ccl:*menu-item*
- :menu-item-title "Save DNET ..."
- :menu-item-action
- #'(lambda ()
- (let* ((dnet
- (wind:menu-dialogue
- (sm:instances 'dnet)
- "Save to disk which DNET?"))
- (file-path
- (pathname
- (ccl:choose-new-file-dialog
- :prompt
- (format nil "Save ~A to ..." dnet)
- :directory
- ;; Use same path but corrected name.
- (let ((prev-path (or (get 'dnet 'sm::$SM-instance-path$)
- sm:*default-instance-file-path*)))
- (make-pathname
- :device (pathname-device prev-path)
- :directory (pathname-directory prev-path)
- :name (symbol-name dnet)
- :type sm:*default-instance-file-type*)))))
- (backup-path
- (make-pathname
- :host (pathname-host file-path)
- :device (pathname-device file-path)
- :directory (pathname-directory file-path)
- :name (pathname-name file-path)
- :type "bak")))
- (if (probe-file file-path)
- (progn
- (if (probe-file backup-path)
- (delete-file backup-path))
- (rename-file file-path backup-path)
- (format T "~&;~A backed up to ~A"
- (namestring file-path)
- (namestring backup-path))))
- (setf *default-instance-file-path*
- (directory-namestring file-path))
- (ccl:eval-enqueue
- `(progn
- (save-dnet ',dnet ',file-path :user)
- (format T "~&;DNET ~A saved to ~S"
- ',dnet
- ',(namestring file-path))))))))
- (hide-item
- (ccl:oneof ccl:*menu-item*
- :menu-item-title "Hide This Menu"
- :menu-item-action
- '(ccl:ask *dnet-menu* (ccl:menu-deinstall))))
- (dnet-menu (ccl:oneof ccl:*menu*
- :menu-title "DNET"
- :menu-items (list browse-item
- line-item
- destroy-dnet-item
- save-dnet-item
- line-item
- hide-item))))
- (ccl:ask dnet-menu (ccl:menu-install))
- (ccl:ask line-item (ccl:menu-item-disable))
- ;; Menu-dispose dumped from version 1.3.1?
- (if (and (boundp '*dnet-menu*)
- (typep *dnet-menu* ccl:*menu*))
- (ccl:ask *dnet-menu* (ccl:menu-deinstall)))
- dnet-menu))
-
- (ccl:ask ccl:*tools-menu*
- (ccl:add-menu-items
- (ccl:oneof ccl:*menu-item*
- :menu-item-title "Restore DNET Menu"
- :menu-item-action
- #'(lambda ()
- (ccl:ask *dnet-menu*
- (unless (ccl:menu-installed-p) (ccl:menu-install)))))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (provide :DNET-BROWSER)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; EOF
-